const i18next = require('i18next');
const Backend = require('i18next-fs-backend');
const path = require('path');

class I18nManager {
    constructor() {
        this.init();
    }

    async init() {
        await i18next
            .use(Backend)
            .init({
                lng: 'en', // default language
                fallbackLng: 'en',
                debug: false,
                backend: {
                    loadPath: path.join(__dirname, '../locales/{{lng}}/translation.json')
                },
                interpolation: {
                    escapeValue: false
                }
            });
    }

    setLanguage(lang) {
        i18next.changeLanguage(lang);
    }

    t(key, options) {
        return i18next.t(key, options);
    }

    getCurrentLanguage() {
        return i18next.language;
    }

    getAvailableLanguages() {
        return ['en', 'zh'];
    }
}

module.exports = I18nManager;